package com.java.controller;

import com.java.model.AdvertisersAccount;
import com.java.model.Result;
import com.java.service.AdvertisersAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/advertisersaccount")
public class AdvertisersAccountController {

    @Autowired
    private AdvertisersAccountService advertisersAccountService;

    /**
     * 广告主用户页面跳转
     * @return
     */
    @GetMapping("/list")
    public String list() {
        return "/advertisersaccount/list";
    }

    /**
     * 查询广告主列表
     * @param advertisersAccount
     * @return
     */
    @PostMapping("/toList")
    @ResponseBody
    public Result toList(AdvertisersAccount advertisersAccount) {
        return advertisersAccountService.list(advertisersAccount);
    }

    /**
     * 跳转到广告主编辑访问顾问
     * @param id
     * @param model
     * @return
     */
    @GetMapping("/edit")
    public String edit(int id, Model model) {
        Result result = advertisersAccountService.get(id);
        if (result.getCode().equals('0')) {
            model.addAttribute("advertisersaccount", result.getData());
        }

        return "/advertisersaccount/edit";
    }

    /**
     * 广告主编辑访问顾问
     * @param advertisersAccount
     * @return
     */
    @PostMapping("/modify")
    @ResponseBody
    public Result remove(@RequestBody AdvertisersAccount advertisersAccount) {
        return advertisersAccountService.modify(advertisersAccount);
    }

    /**
     * 跳转到查看公司详情
     * @param id
     * @param model
     * @return
     */
    @GetMapping("/details")
    public String details(int id, Model model) {
        Result result = advertisersAccountService.get(id);
        if (result.getCode().equals("0")) {
            model.addAttribute("details", result.getData());
        }

        return "/advertisersaccount/details";
    }

    /**
     * 广告主的启用禁用
     * @return
     */
    @PostMapping("/updateStatus")
    @ResponseBody
    public Result updateStatus(int[] ids, String status) {
        return advertisersAccountService.updateStatus(ids, status);
    }


    /**
     * 广告主钱包信息页面跳转
     */
    @GetMapping("/wallet")
    public String wallet(){
        return "financial/wallet";
    }

    /**
     * 查询广告主列表
     * @param advertisersAccount
     * @return
     */
    @PostMapping("/toWallet")
    @ResponseBody
    public Result toWallet(AdvertisersAccount advertisersAccount) {
        return advertisersAccountService.wallet(advertisersAccount);
    }
}
